package com.skwyb.form.controller.system;

import com.skwyb.form.bean.dto.SysDictType;
import com.skwyb.form.bean.req.IdReq;
import com.skwyb.form.core.BusinessException;
import com.skwyb.form.core.ObjectResult;
import com.skwyb.form.service.system.DictTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
@RequestMapping("/admin/dictType")
public class DictTypeController {

    @Autowired
    private DictTypeService typeService;

    @GetMapping("/list")
    public ObjectResult listType() {
        return new ObjectResult(typeService.list());
    }

    @PostMapping("/save")
    public ObjectResult saveType(@Valid SysDictType record) throws BusinessException {
        return new ObjectResult(typeService.saveOrUpdate(record));
    }

    @PostMapping("/get")
    public ObjectResult getTypeDetail(@Valid IdReq req) throws BusinessException {
        return new ObjectResult(typeService.getById(req.getId()));
    }

    @PostMapping("/delete")
    public ObjectResult deleteType(@Valid IdReq req) throws BusinessException {
        return new ObjectResult(typeService.removeById(req.getId()));
    }
}
